package com.whpost.service.dao.wx;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.whpost.service.entity.wx.TWxToken;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;

public interface TWxTokenDao extends BaseMapper<TWxToken> {

    //获取
    @Select("select access_token from t_wx_token where end_date > #{nowDate} and lx=#{lx} and wx_id=#{wx_id}")
    String getToken(@Param(value = "lx") String lx,@Param(value = "nowDate") Date nowDate,@Param(value = "wx_id") Long wx_id);

    //删除
    @Delete("delete from t_wx_token where lx=#{0} and wx_id=#{wx_id}")
    int delToken(String lx,@Param(value = "wx_id") Long wx_id);

    //保存
    @Insert("insert into t_wx_token (access_token,expires_in,expires_date,end_date,lx,wx_id) VALUES(#{access_token},#{expires_in},#{nowDate},#{nowDate}+#{expires_in}/24/60/60,#{lx},#{wx_id})")
    int saveToken(@Param(value = "access_token") String access_token, @Param(value = "expires_in") String expires_in, @Param(value = "lx") String lx,@Param(value = "nowDate") Date nowDate,@Param(value = "wx_id") Long wx_id);
}